package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;

import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class Practice4DrawPointView extends View {


    private static final float STROKE_WIDTH= 80f;

    public Practice4DrawPointView(Context context) {
        super(context);
        initPaint();
    }

    public Practice4DrawPointView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    public Practice4DrawPointView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint();
    }
    private Paint mPaint;
    private void initPaint() {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        练习内容：使用 canvas.drawPoint() 方法画点
//        一个圆点，一个方点
//        圆点和方点的切换使用 paint.setStrokeCap(cap)：`ROUND` 是圆点，`BUTT` 或 `SQUARE` 是方点

        int centerX = getWidth()/2;
        int centerY = getHeight()/2;

        mPaint.setStrokeWidth(STROKE_WIDTH);
        mPaint.setStrokeCap(Paint.Cap.BUTT);

        canvas.drawPoint(centerX-50,centerY-50,mPaint);

        mPaint.setStrokeCap(Paint.Cap.ROUND);

        canvas.drawPoint(centerX+50,centerY-50,mPaint);

        mPaint.setStrokeCap(Paint.Cap.SQUARE);

        canvas.drawPoint(centerX-50,centerY+50,mPaint);
    }
}
